package com.atguigu.practice;

import org.junit.Test;

import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;
public class EmployeeTest {
    @Test
    public void test() {
        Comparator<Employee> com=(o1,o2)->{
            if(o1.getBirthday().getYear()<o2.getBirthday().getYear()){
                return -1;
            }else if(o1.getBirthday().getYear()>o2.getBirthday().getYear()){
                return 1;
            }else{
                if(o1.getBirthday().getMonth()<o2.getBirthday().getMonth()){
                    return -1;
                }else if(o1.getBirthday().getMonth()>o2.getBirthday().getMonth()){
                    return 1;
                }else{
                    if(o1.getBirthday().getDay()<o2.getBirthday().getDay()){
                        return -1;
                    }else if(o1.getBirthday().getDay()>o2.getBirthday().getDay()){
                        return 1;
                    }else{
                        return 0;
                    }
                }
            }
        };
        TreeSet set = new TreeSet(com);
        Employee e1 = new Employee("刘德华", 55, new MyDate(1967, 12, 11));
        Employee e2 = new Employee("hz", 19, new MyDate(2002, 12, 26));
        Employee e3 = new Employee("zl", 20, new MyDate(2003, 1, 23));
        Employee e4 = new Employee("捷豹", 20, new MyDate(2002, 12, 15));
        Employee e5 = new Employee("叶", 19, new MyDate(2002, 11, 6));
        set.add(e1);
        set.add(e2);
        set.add(e3);
        set.add(e4);
        set.add(e5);
        Iterator iterator=set.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }
}
